import { http } from "@/util/request/index";
import config from "@/common/config";

// 省市区数据
export const apiConfigAddress = (params) => {
  return http.get("/api/config/address/", {
    params,
  });
};

// 文件上传
export const uploadFile = (file) => {
  return new Promise((resolve, reject) => {
    uni.uploadFile({
      url: config.baseUrl + "/api/upload/",
      header: {
        Authorization: "Bearer " + uni.getStorageSync("token"),
      },
      name: "file",
      filePath: file,
      success: (uploadFileRes) => {
        if (uploadFileRes.statusCode == 200) {
          resolve(JSON.parse(uploadFileRes.data));
        } else {
          uni.showToast({
            title: uploadFileRes.message,
            icon: "none",
          });
        }
      },
      fail: (error) => {
        console.log("上传失败=", error);
        reject(error);
      },
    });
  });
};

export const getBannerList = () => {
  return http.get("/api/banners/");
};

export const getSystemConfig = (params) => {
  return http.get("/api/config/", { params });
};
